package cn.yitun.chat.yitunservercommonlib.databind.jackson;

import cn.yitun.chat.yituncommonutil.YitunDateUtil;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.util.Date;

/**
 * 
 * Description 时间格式序列化 <br>
 * Date 2019-04-29 09:25:18<br>
 * 
 * @author yitun
 * @version 1.1
 */
public class CustomDateSerializer extends JsonSerializer<Date> {
	@Override
	public void serialize(Date value, JsonGenerator jsonGenerator, SerializerProvider serializers) throws IOException {
		if (null != value) {
			String date = YitunDateUtil.format(value, YitunDateUtil.FORMAT_DATE_TIME);
			jsonGenerator.writeString(date);
		}
	}
}
